<template>

</template>

<script>
export default {
  data() {
    return {
      qrcode: "",
      checkcode: false,
      userId: ""
    };
  },

  mounted() {
    // console.log($)
    // console.log(this.$http)

    var code = this.$route.query.code;

    if (code.length !== 8) {
      //跳转到防伪码页面
      this.$router.push({ path: "/" });
    } else {
      this.qrcode = code;
      var cookie = document.cookie.split(";");
      var cookies = [];
      for (var i = 0; i < cookie.length; i++) {
        var temp = cookie[i].trim().split("=");
        cookies[temp[0]] = temp[1];
      }
      // console.log(cookies);
      var id = cookies["id"];
      // alert(id);
      if (!id) {
        window.location.href =
          "http://wztest.wofew.com/api/Main/login_sao?c=" + code;
      }
      // this.userLogin();
      this.getProduct();
    }
  },
  methods: {
    checkinput() {},
    getProduct() {
      var that = this;
      var cookie = document.cookie.split(";");
      var cookies = [];
      for (var i = 0; i < cookie.length; i++) {
        var temp = cookie[i].trim().split("=");
        cookies[temp[0]] = temp[1];
      }
      // console.log(cookies);
      var id = cookies["id"];
      // alert(id);
      if (!id) {
        window.location.href =
          "http://wztest.wofew.com/api/Main/login_sao?c=" + code;
      }
      $.ajax({
        type: "get",
        url: `${this.$store.state.globalIp}/api/Main/check_bind`,
        data: {
          code: this.qrcode,
          id: id
        },
        dataType: "json",
        success(result) {
          if (result.message == "成功") {
            var data = result.data;
            if (data.status == 0) {
              that.$router.push({ path: "inquire", query: data }); // 未绑定
            } else {
              that.$router.push({ path: "result", query: data }); //绑定
            }
          } else {
            that.checkcode = true;
            setTimeout(() => {
              that.checkcode = false;
            }, 3000);
          }
        }
      });
    }
    // userLogin() {
    //   var that = this;
    //   $.ajax({
    //     type: "get",
    //     url: `${this.$store.state.globalIp}/api/Main/login`,
    //     data: {

    //     },
    //     dataType: "json",
    //     success(result) {
    //       if (result.message == "成功") {
    //         var data = result.data;
    //        //在这里得到id
    //        var id=result.data.id;
    //        that.userId=id;
    //        that.getProduct();
    //       } else {

    //       }
    //     }
    //   });
    // }
  }
};
</script>

<style>
</style>
